#_*_ coding: utf-8
"""
author: ning.luo
create_date: 2020/06/03
last_update: 2020/06/03
"""

# import unittest
#
# class TestLabelService(unittest.TestCase):
#     '''标签服务接口'''
#
#     a = 1
#
#     def test_1(self):
#         self.a = 2
#         print('a', self.a)
#         return self.a
#
#     def test_2(self):
#         b = self.test_1()
#         print('b', b)

class Node:
    def __init__(self, data=None, next=None):
        self.data = data
        self.next = next

def rev_link(head):
    if head.next == None:
        return head
    last = rev_link(head.next)
    head.next.next = head
    head.next = None
    return last

def rev_link_1(link):
    if link.next == None:
        return link
    node_list = list()
    pre = link
    while pre:
        node_list.append(pre)
        pre = pre.next
    node_list[0].next = None
    for i in range(1, len(node_list)):
        node_list[i].next = node_list[i-1]
    return node_list[-1]

def rev_link_2(link):
    if link.next == None:
        return link
    pre = link
    cur = pre.next
    pre.next = None
    while cur:
        temp = cur.next
        cur.next = pre
        pre = cur
        cur = temp
    return pre

if __name__ == "__main__":
    link = Node(1, Node(2, Node(3, Node(4, Node(5, Node(6, Node(7, Node(8, Node(9)))))))))
    # link = Node(1, Node(2))
    # rev_link_demo = rev_link(link)
    # rev_link_demo = rev_link_1(link)
    rev_link_demo = rev_link_2(link)
    while rev_link_demo:
        print(rev_link_demo.data)
        rev_link_demo = rev_link_demo.next
